<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------
namespace Api\Service;

class ImageSheetService{
	
    /**
     * 保存图片和曲谱的关系
     * @return unknown
     */
    public function save($images, $sheet_id){
        //step-0: 先删除历史数据
        $Model = M('ImageSheet');
        $Model->where(array('sheet_id'=>$sheet_id))->delete();
        
        //step-1: 组织图片和谱单的关系
        $image_sheet = array();
        foreach ($images as $key=>$image) {
            $image_sheet[] = array(
                'sheet_id' => $sheet_id,
                'image_id' => $image['id'],
                'creator'  => 2,    //系统管理员
                'index'    => $image['index']
            );
        }
        
        //step-2: 批量保存图片和谱单的关系
        return $Model->addAll($image_sheet);
        
	}
	
	
}